package com.ruoyi.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.omg.PortableInterceptor.SUCCESSFUL;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.StringUtils;
import org.apache.commons.collections4.CollectionUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.IwebshopAreas;
import com.ruoyi.system.service.IIwebshopAreasService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区信息Controller
 *
 * @author gf
 * @date 2024-11-26
 */
@RestController
@RequestMapping("/system/iwebshopAreas")
public class IwebshopAreasController extends BaseController {
    @Autowired
    private IIwebshopAreasService iwebshopAreasService;

    /**
     * 查询地区信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IwebshopAreas iwebshopAreas) {
        startPage();
        List<IwebshopAreas> list = iwebshopAreasService.selectIwebshopAreasList(iwebshopAreas);
        return getDataTable(list);
    }

    /**
     * 导出地区信息列表
     */
    @Log(title = "地区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, IwebshopAreas iwebshopAreas) {
        List<IwebshopAreas> list = iwebshopAreasService.selectIwebshopAreasList(iwebshopAreas);
        ExcelUtil<IwebshopAreas> util = new ExcelUtil<>(IwebshopAreas.class);
        util.exportExcel(response, list, "地区信息数据");
    }

    /**
     * 获取地区信息详细信息
     */
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Integer areaId) {
        return success(iwebshopAreasService.selectIwebshopAreasByAreaId(areaId));
    }

    /**
     * 新增地区信息
     */
    @Log(title = "地区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody IwebshopAreas iwebshopAreas) {
        return toAjax(iwebshopAreasService.insertIwebshopAreas(iwebshopAreas));
    }

    /**
     * 修改地区信息
     */
    @Log(title = "地区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody IwebshopAreas iwebshopAreas) {
        return toAjax(iwebshopAreasService.updateIwebshopAreas(iwebshopAreas));
    }

    /**
     * 删除地区信息
     */
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable Integer[] areaIds) {
        return toAjax(iwebshopAreasService.deleteIwebshopAreasByAreaIds(areaIds));
    }

    /**
     * 逻辑删除地区信息
     */
    @Log(title = "地区信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/logicDel/{areaIds}")
    public AjaxResult logicDel(@PathVariable Integer[] areaIds) {
        return toAjax(iwebshopAreasService.logicDeleteIwebshopAreasByAreaIds(areaIds));
    }

    @GetMapping("/listParentId")
    public AjaxResult listParentId() {
        return success(iwebshopAreasService.selectIwebshopAreasListParentId());
    }
}
